PRG 1.0 TXT

/*
*/

//-----------------------------------------------------------------------------
// [CONFIG]

include "..\program_include.ocf"

object Program
{
	type		= e_program.DIFFUSE_SA;
	layer_bits	= e_render_layer_bits.OPAQUE;
	
	ubo_data	= array /*UBO*/ {
		{ "inMaterial",  e_program_data.MATERIAL }
	}

	textures	= array /*ProgramTexture*/ {
		{ "unDiffuseMap", e_texture.DIFFUSE },
		{ "unJointData",  e_texture.JOINTS_ARRAY },
		{ "unWeightData", e_texture.WEIGHTS_ARRAY }
	}
	
	uniforms	= array /*string*/ {
		"transform", "unTransform."
	}
}


//-----------------------------------------------------------------------------
// [VERTEX]
#line 34
#version 330 core
#pragma optimize(on)

#define ATTR_POSITION	0
#define ATTR_TEXCOORD	2

layout(location = ATTR_TEXCOORD) in vec2	inTexcoord;
layout(location = ATTR_POSITION) in vec2	inWeight;		// start index, count

uniform samplerBuffer	unJointData;			// RGBA32F : quat (4), pos (3), empty (1)
uniform samplerBuffer	unWeightData;			// RGB32F  : pos (3), joint index (1), bias (1), empty (1)

uniform struct TTransform {
	mat4	MVP;
} unTransform;


out	TVertexData {
	vec2	vTexcoord;
} Output;


vec3 RotateVec(in vec4 qleft, in vec3 vright)
{
	vec3	uv,
			uuv,
			qvec = vec3(qleft);

	uv	= cross( qvec, vright );
	uuv	= cross( qvec, uv ) * 2.0;
	uv	*= 2.0 * qleft.w;
	
	return vright + uv + uuv;
}


void main()
{
	vec3	position = vec3(0.0);
	int		count	 = int( inWeight[1] );
	int		start	 = int( inWeight[0] );
	
	for (int i = 0; i < count; ++i)
	{
		int		idx		= ( start + i ) * 2;
		
		// read weight data
		vec3	w_pos	= texelFetch( unWeightData, idx + 0 ).rgb;
		vec3	w_data	= texelFetch( unWeightData, idx + 1 ).rgb;
		int		joint	= floatBitsToInt( w_data.x );
		float	bias	= w_data.y;
		
		idx = joint * 2;
		
		// read joint data
		vec4	orient	= texelFetch( unJointData, idx + 0 ).rgba;
		vec3	j_pos	= texelFetch( unJointData, idx + 1 ).rgb;
		
		//position += ( j_pos + RotateVec( orient, w_pos ) ) * bias;
		position += j_pos + w_pos * bias;
	}
	
	//position *= 0.0000001;
	//position += vec3( inTexcoord, 1.0 ) * 10000.0;
	
	gl_Position		 = unTransform.MVP * vec4(position * 100.0, 1.0);
	//vec4( clamp( position, vec3(-10.0), vec3(10.0) ), 1.0 );
	Output.vTexcoord = inTexcoord;
}


//-----------------------------------------------------------------------------
/*/ [GE OMETRY]

#version 330 core
#pragma optimize(on)

layout(triangles) in;
layout(triangle_strip, max_vertices = 3) out;

uniform struct TTransform {
	mat4	MVP;
} unTransform;

in	TVertexData {
	vec2	vTexcoord;
} Input[];

out	TGeomData {
	vec2	vTexcoord;
} Output;

/*
	   /4--------/2
	  / |       / |
	 /  |      /  |
	6---------0   |
	|  /5- - -|- -3
	| /       |  /
	|/        | /
	7---------1/
	
	0 - max
	5 - min
	
	first strip:  0,1,2,3,4,5,6,7
	second strip: 4,2,6,0,7,1,5,3
*

void Vertex(in vec3 pos)
{
	gl_Position = vec4( pos, 1.0 ) * unTransform.MVP;
	Output.vTexcoord = vec2(0,0);
	EmitVertex();
}

void main()
{
	vec3	v_min = vec3(-10) + gl_in[0].gl_Position.xyz;
	vec3	v_max = vec3(10)  + gl_in[1].gl_Position.xyz;

	/*0* Vertex( v_max );
	/*1* Vertex( vec3( v_max.xy, v_min.z ) );
	/*2* Vertex( vec3( v_max.x, v_min.y, v_max.z ) );
	EndPrimitive();
}
*/

//-----------------------------------------------------------------------------
// [FRAGMENT]

#version 330 core
#pragma optimize(on)

layout(location = 0) out vec4	outColor;

uniform sampler2D	unDiffuseMap;

layout(std140)
uniform inMaterial {
	vec3	vAmbientColor;
	vec4	vDiffuseColor;
	vec3	vSpecularColor;
	vec3	vEmissionColor;
	float	fShininess;
} unMaterial;


in	TVertexData {
	vec2	vTexcoord;
} Input;


void main()
{
	outColor = texture( unDiffuseMap, Input.vTexcoord ) * unMaterial.vDiffuseColor;
	outColor.rgb += unMaterial.vAmbientColor;
	outColor.rgb += unMaterial.vEmissionColor;
}

// [END]
